package xyz.eden.gateway.springcloud.admin.component.route.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class YamlUtil {

    private static ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    public static <T> T deserializeObject(String s, TypeReference<T> typeReference) {
        try {
            return mapper.readValue(s, typeReference);
        } catch (JsonProcessingException e) {
            log.error("Yaml Str Deserialize Object Exception, msg: [{}].", e.getMessage(), e);
            return null;
        }
    }
}
